//
//  ByChaseNumberManageVC.m
//  caipiao_ios
//
//  Created by mc on 2018/8/13.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByChaseNumberManageVC.h"
#import "ByChaseNumberListCell.h"
#import "ByChaseNumberVC.h"

@interface ByChaseNumberManageVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation ByChaseNumberManageVC

- (NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _dataArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addLeftBackBarButtonItem];
    self.title = @"追号管理";
    
    [self initViews];
    [self loadData];
    // Do any additional setup after loading the view.
}
- (void)loadData{
    ByNetModel *netModel = [[ByNetModel alloc] init];
    [ByCoreToolAlert showLoadind:@"加载中"];
    [ByApiOther chasingIndex:netModel success:^(ByNetBaseResult *result) {
        [ByCoreToolAlert hideHud];
        [self.dataArray removeAllObjects];
        NSArray *array = result.data[@"data"];
        if ([array isKindOfClass:[NSArray class]]) {
            for (NSDictionary *dic in array) {
                ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dic];
                [self.dataArray addObject:netModel];
            }
        }
       
        [self.tableView reloadData];
        SLog(@"追号详情 = %@",result.data);
    } failure:^(ByNetBaseResult *result) {
        [ByCoreToolAlert showFailureWithText:result.msg];
        [self.dataArray removeAllObjects];
        [self.tableView reloadData];
    }];
}

- (void)initViews{
    
    self.view.backgroundColor = BY_BACKGROUND_COLOR;
    self.tableView = [[UITableView alloc] init];
    self.tableView.backgroundColor = BY_BACKGROUND_COLOR;
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
       
        if (@available(ios 11.0,*)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(0);
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(0);
        } else {
            make.top.equalTo(self.view).offset(0);
            make.bottom.equalTo(self.view).offset(0);
        }
    }];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ByChaseNumberListCell *cell = [ByChaseNumberListCell cellWithTableView:tableView];
    ByNetModel *netModel = [self.dataArray objectAtIndex:indexPath.row];
    cell.netModel = netModel;
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 10 + 45 + 5 + 20 + 9 * 2;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ByChaseNumberVC *vc = [[ByChaseNumberVC alloc] init];
    ByNetModel *netModel = [self.dataArray objectAtIndex:indexPath.row];
    vc.netModel = netModel;
    [self by_normalPush:vc hasNavi:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
